/*    */ package com.qmsk.business.activity.activityrpt.controller;
/*    */ 
/*    */ import com.qmsk.business.activity.activityrpt.dao.ActivityRptDAO;
/*    */ import com.qmsk.business.manage.cust.dao.CustDAO;
/*    */ import com.qmsk.business.weixin.customMenu.customer.CustomerInfo;
/*    */ import com.qmsk.business.weixin.customMenu.wxMapUtils.WxMapUtils;
/*    */ import com.utils.gson.in.GsonHeadOneRow;
/*    */ import com.utils.gson.in.ParserDataSetJson;
/*    */ import com.utils.jdbc.connection.DbConnection;
/*    */ import com.utils.web.RequestUtils;
/*    */ import com.utils.web.ResponseUtils;
/*    */ import java.util.Date;
/*    */ import java.util.List;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.transaction.annotation.Transactional;
/*    */ import org.springframework.web.bind.annotation.PathVariable;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ 
/*    */ @Controller
/*    */ @RequestMapping({"/activityrpt"})
/*    */ public class ActivityRptController
/*    */ {
/* 32 */   private static final Logger logger = Logger.getLogger(ActivityRptController.class);
/*    */ 
/*    */   @Autowired
/*    */   private ActivityRptDAO dao;
/*    */ 
/*    */   @Autowired
/*    */   private CustDAO custDao;
/*    */ 
/*    */   @Transactional(rollbackFor={Exception.class})
/*    */   @RequestMapping(value={"insert/wxInsert/openId/{openId}/actId/{actId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*    */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("actId") Long actId, @PathVariable("openId") String openId)
/*    */   {
/*    */     try
/*    */     {
/* 53 */       ParserDataSetJson p = new ParserDataSetJson(
/* 54 */         request.getParameter("data"));
/* 55 */       if ((p == null) || (!(p.isExistsInsertRows()))) {
/* 56 */         ResponseUtils.setErrorMsgResponse(RequestUtils.getReadJsonDataErrorMessage(request), response);
/* 57 */         return;
/*    */       }
/* 59 */       GsonHeadOneRow g = (GsonHeadOneRow)p.getListInsertRows().get(0);
/* 60 */       if (g == null) {
/* 61 */         int nResult = this.dao.isExistByActIdAndOpenId(actId, openId);
/* 62 */         if (nResult == 1) {
/* 63 */           ResponseUtils.setErrorMsgResponse("您已经参加了该活动！", response);
/* 64 */           return;
/*    */         }
/* 66 */         CustomerInfo c = WxMapUtils.getCustInfoOfOpenId(openId);
/* 67 */         String nickName = null;
/* 68 */         if (c != null) {
/* 69 */           nickName = c.getNickname();
/*    */         }
/* 71 */         nResult = this.dao.insertInfo(actId, Long.valueOf(0L), null, nickName, 
/* 72 */           null, Integer.valueOf(0), new Date(), null, 1, openId);
/* 73 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 74 */           RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 75 */           response);
/* 76 */         return;
/*    */       }
/* 78 */       int nResult = 0;
/* 79 */       Long cusId = (Long)g.getValueOfName("CustomerID");
/* 80 */       nResult = this.dao.isExistByActIdAndCustId(actId, cusId);
/* 81 */       if (nResult == 1) {
/* 82 */         ResponseUtils.setErrorMsgResponse("您已经参加了该活动！", response);
/* 83 */         return;
/*    */       }
/* 85 */       String linkPhone = (String)g.getValueOfName("Mp");
/* 86 */       String linkMan = (String)g.getValueOfName("CustomerName");
/* 87 */       String idNumber = (String)g.getValueOfName("IDNumber");
/* 88 */       Integer status = Integer.valueOf(0);
/* 89 */       Date auditDate = new Date();
/* 90 */       String address = (String)g.getValueOfName("Address");
/*    */ 
/* 92 */       nResult = this.dao.insertInfo(actId, cusId, linkPhone, linkMan, 
/* 93 */         idNumber, status, auditDate, address, 1, openId);
/*    */ 
/* 95 */       if (nResult > 0)
/* 96 */         DbConnection.commit();
/*    */       else {
/* 98 */         DbConnection.rollback();
/*    */       }
/* 100 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 101 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 102 */         response);
/*    */     } catch (Exception e) {
/* 104 */       logger.error(e);
/* 105 */       DbConnection.rollback();
/* 106 */       ResponseUtils.setErrorMsgResponse(
/* 107 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 108 */         e.getMessage(), response);
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.activity.activityrpt.controller.ActivityRptController
 * JD-Core Version:    0.5.3
 */